package java_learn.java_jinjie.DataStructure;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * java.util.LinkedHashSet集合 extends HashSet集合
 * LinkedHashSet集合特点:
 * 底层是一个哈希表(数组+链表/红黑树)+链表:多了一条链表(记录元素的存储顺序),保证元素有序
 */
public class DemoLinkedHashSet {
    public static void main(String[] args) {
        HashSet<Person> set = new HashSet<>();
        Person p1 = new Person("a", 20);
        Person p2 = new Person("a", 18);
        Person p3 = new Person("b", 19);
        set.add(p1);
        set.add(p2);
        set.add(p3);

        Set<Person> Set = new LinkedHashSet<>();
        Person p4 = new Person("a", 20);
        Person p5 = new Person("a", 18);
        Person p6 = new Person("b", 19);
        Set.add(p1);
        Set.add(p2);
        Set.add(p3);
        System.out.println(set);
        System.out.println(Set);
    }
}
